<!--tvm票款差异协查-->
<template>
  <div class="TvmTicketCYXC HuikuiInfo el-card is-always-shadow el-card__body">
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      @close="closed"
      width="80%">
      <div style="line-height: 40px;background-color: #fcf7f7;padding-left: 15px">
        <span>线路：</span><span>{{getLineName(formData.lineCode)}}</span>
        <span style="margin-left: 20px">站点：</span><span>{{getStationName(formData.lineCode,formData.stationCode)}}</span>
        <span style="margin-left: 20px">TVM编号：</span><span>{{formData.tvmOrder}}</span>
        <span style="margin-left: 20px"> 收入日期：</span><span>{{formData.settleTime}}</span>
      </div>
      <avue-form :option="option" v-model="formData" @submit="handleSubmit" class="huikuiForm">

        <template slot-scope="{scope}" slot="dynamic">
          <avue-crud
            ref="TvmTicketCYXC"
            :option="listOption1"
            :data="formData.list1">
          </avue-crud>
        </template>

<!--        <template slot-scope="{scope}" slot="dynamic2">-->
<!--          <avue-crud-->
<!--            ref="TvmTicketCYXC"-->
<!--            :option="listOption2"-->
<!--            :data="formData.list2">-->
<!--          </avue-crud>-->
<!--        </template>-->

<!--        <template slot-scope="{scope}" slot="dynamic3">-->
<!--          <avue-crud-->
<!--            ref="TvmTicketCYXC"-->
<!--            :option="listOption3"-->
<!--            :data="formData.list3">-->
<!--          </avue-crud>-->
<!--        </template>-->

        <template slot-scope="scope" slot="menuForm">
          <el-button type="primary" @click="closed">返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>


<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import ExportJsonExcel from "js-export-excel";

  import {
    clearSelect,
    electromeReasons,
    getQianxiangType,
    qianxiangType,
    selectReasons,
    fenExYuangettoFixed,
    getLineName,
    getStationName
  } from "../../../../api/subwayRat/commonCheck";
  import {
    editor_xw_SwAuTvmBoxAmountDifference,
    get_xw_SwAuTvmBoxAmountDifference,
  } from "../../../../api/stationTiecketManager/shuJuXieChaGuanLi/TVM/XT/TVMXTSJCY/JDZYDLCK";
  import {
    get_xw_SwAuTvmMoneyAssistList,
    xw_TVM_pkcy_cols1, xw_TVM_pkcy_cols2,
    xw_TVM_pkcy_cols3
  } from "../../../../api/stationTiecketManager/shuJuXieChaGuanLi/TVM/TVMPiaoKuanCYXX";
  export default {
    components:{
    },
    data() {
      return {
        dialogVisible:true,
        //1预览，2编辑，
        showType:1,
        listOption1:xw_TVM_pkcy_cols1,
        listOption2:xw_TVM_pkcy_cols2,
        listOption3:xw_TVM_pkcy_cols3,
        formData:{
          list1: [],
          list2: [],
          list3: [],
        },
        option:{}
    }
    },
    created() {
    },
    methods: {
      getLineName,
      getStationName,
      fenExYuangettoFixed,
      getQianxiangType,
      handleSubmit(form,done){
        // delete param.dynamic;
	//
	if(''==this.formData.kyReplyReason ||this.formData.kyReplyReason==undefined){
          this.$message.error("请选择车站回馈差异原因！");
	  done(false);
          return;
        }	
	if(''==this.formData.kyReplayConent || this.formData.kyReplayConent==undefined){
	   this.$message.error("请填写车站详细描述！");
          done(false);
          return;
	}
	if(this.formData.kyReplayConent.length>500){
	   this.$message.error("字数超过限制，请修改在500字以内！");
           done(false);
          return;
	}
        let param={};
        param.id=this.formData.id;
        param.replyActualMoney=this.formData.list1[0].replyActualMoney;
        param.kyReplyReason=this.formData.kyReplyReason;
        param.kyReplayConent=this.formData.kyReplayConent;
        param.kyOperatorCode=this.$store.getters.userInfo.userCode;
        param.kyOperatorId=this.$store.getters.userInfo.userId;
        this.formatAmount(param,false);
        /*
	editor_xw_SwAuTvmBoxAmountDifference(param).then(res=>{
          if(res.data.code==0){
            this.$message.success("操作成功！");
            this.$parent.getList();
            this.closed();
          }else{
            this.$message.error("操作失败！");
          }
        });
	*/
	// 3. 发起异步请求
	editor_xw_SwAuTvmBoxAmountDifference(param).then(res => {
	    // 4. 请求完成后操作
	    if (res.data.code === 0) {
	      this.$message.success("操作成功！");
	      this.$parent.getList();
	      this.closed();
	    } else {
	      this.$message.error("操作失败！");
	    }
	  }).catch(error => {
	    // 5. 错误处理
	    this.$message.error("请求异常: " + (error.message || "未知错误"));
	  }).finally(() => {
	    done();  // 关键修复：无论成功失败都释放按钮
	  });
        
      },
      recallShow(row,showType){
        this.showType=showType;
        if(2 == this.showType){
          this.listOption1.column[5].disabled = false;
        }else{
          this.listOption1.column[5].disabled = true;
        }
        Object.assign(this.formData,row);
        this.getOption();
        this.formData={}
        let th=this;
        get_xw_SwAuTvmMoneyAssistList({id:row.id}).then((res)=>{
          // th.formData.boxUninstallStatus=res.data.data.list[0].boxUninstallStatus;
          // th.formData.cashBoxType=res.data.data.list[0].boxCashType;
          th.formData.$cellEdit=true;
          let will=JSON.parse(JSON.stringify(th.formData));
          this.formatAmount(will,true);
          th.formData.list1=[will];
          console.log(this.formData)
        }).catch((e)=>{
          this.$message.error("获取数据失败！");
        })
      },
      formatAmount(row,isYuan){
        if(isYuan){
          row.systemMoney=fenExYuangettoFixed(row,'systemMoney');
          row.tvmUnloadMoney=fenExYuangettoFixed(row,'tvmUnloadMoney');
          row.replyDsiplayMoney=fenExYuangettoFixed(row,'replyDsiplayMoney');
          row.diffUnloadDisplayMoney=fenExYuangettoFixed(row,'diffUnloadDisplayMoney');
          //row.actualMoney=fenExYuangettoFixed(row,'actualMoney');
          //row.replyActualMoney=fenExYuangettoFixed(row,'replyActualMoney');
          row.replyLoadUnloadMoney=fenExYuangettoFixed(row,'replyLoadUnloadMoney');
          row.diffLoadUnloadMoney=fenExYuangettoFixed(row,'diffLoadUnloadMoney');
          row.supplementMoney=fenExYuangettoFixed(row,'supplementMoney');
          row.replySupplementMoney=fenExYuangettoFixed(row,'replySupplementMoney');
          row.diffSupplementMoney=fenExYuangettoFixed(row,'diffSupplementMoney');
          //row.handOutMoney=fenExYuangettoFixed(row,'handOutMoney');
        }else{
          row.systemMoney=Number(row.systemMoney)*100;
          row.tvmUnloadMoney=Number(row.tvmUnloadMoney)*100;
          row.replyDsiplayMoney=Number(row.replyDsiplayMoney)*100;
          row.diffUnloadDisplayMoney=Number(row.diffUnloadDisplayMoney)*100;
          //row.actualMoney=Number(row.actualMoney)*100;
          //row.replyActualMoney=Number(row.replyActualMoney)*100;
          row.replyLoadUnloadMoney=Number(row.replyLoadUnloadMoney)*100;
          row.diffLoadUnloadMoney=Number(row.diffLoadUnloadMoney)*100;
          row.supplementMoney=Number(row.supplementMoney)*100;
          row.replySupplementMoney=Number(row.replySupplementMoney)*100;
          row.diffSupplementMoney=Number(row.diffSupplementMoney)*100;
          //row.handOutMoney=Number(row.handOutMoney)*100;
        }
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.isShowDia=false;
      },
      getOption(){
        this.option={
          submitBtn:this.showType==2,
          emptyBtn:false,
          submitText:'保存',
          // emptyText:'返回',
          group:[
            {
              icon:'',
              sortable:true,
              label: '钱箱操作信息回馈',
              // collapse:false,
              prop: 'group1',
              indexLabel:"#",
              column: [{
                label: '',
                prop: 'dynamic',
                span:24,
                formslot:true
              }
              ]
            },
            // {
            //   icon:'',
            //   sortable:true,
            //   label: '机电-SC系统钱箱信息回馈',
            //   collapse:false,
            //   prop: 'group2',
            //   indexLabel:"#",
            //   column: [{
            //     label: '',
            //     prop: 'dynamic2',
            //     span:24,
            //     formslot:true
            //   }
            //   ]
            // },
            // {
            //   icon:'',
            //   sortable:true,
            //   label: '机电-SC系统信息回馈',
            //   collapse:false,
            //   prop: 'group3',
            //   indexLabel:"#",
            //   column: [{
            //     label: '',
            //     prop: 'dynamic3',
            //     span:24,
            //     formslot:true
            //   }
            //   ]
            // },
            {
              icon:'',
              label: '原因与备注',
              // collapse:false,
              prop: 'group4',
              column: [{
                label: '机电专业回馈差异原因',
                prop: 'replyReason',
                labelWidth:130,
                disabled: true,
                type:'select',
                dicData:electromeReasons(),
              },
                {
                  label: '车站回馈差异原因',
                  prop: 'kyReplyReason',
                  labelWidth:130,
                  disabled: this.showType==1,
                  type:'select',
                  dicData:electromeReasons(),
                },
                {
                  label: '机电专业详细描述',
                  prop: 'replyContent',
                  type: 'textarea',
                  labelWidth:130,
                  disabled: true
                },
                {
                  label: '车站详细描述',
                  prop: 'kyReplayConent',
                  type: 'textarea',
                  labelWidth:130,
                  disabled: this.showType==1,
                },
                {
                  label: '车站备注',
                  prop: 'stationCleanRemark',
                  type: 'textarea',
                  labelWidth:130,
                  disabled:true
                },
                {
                  label: '站长审核意见',
                  prop: 'auditStationOpinion',
                  type: 'textarea',
                  labelWidth:130,
                  disabled:true
                }, {
                  label: '车间票务专业审核意见',
                  prop: 'auditWorkshopOpinion',
                  type: 'textarea',
                  labelWidth:130,
                  disabled:true
                }, {
                  label: '部门票务专业审核意见',
                  prop: 'auditDeptOpinion',
                  type: 'textarea',
                  labelWidth:130,
                  disabled:true
                }
              ]
            }
          ]
        };
        this.isReload=false;
        this.$nextTick(()=>{
          this.isReload=true;
        })
      }
    },
    mounted() {

    }
  }
</script>
<style lang="scss">
  .TvmTicketCYXC.HuikuiInfo{
    .avue-group[index='3']{
      .el-form-item{
        min-width: 450px;
      }
      .avue-form__row{
        width: 70%;
      }
    }
  }
</style>
